﻿/**
 * 
 * @authors Riche
 * @date    2016-07-05 10:39:22
 * @version 1.1.0
 */
 var articleID = $.getUrlVar("articleID");
 var annexID = $.getUrlVar("annexID");
var forword = encodeURIComponent(window.location.href);
var backUrl = $.getUrlVar("back");

var info=new Vue({
  el:"#app",
  data:{
    info:{},
    score:0,
    addShow: false,
    showModal : false,
    users:[],
    title:'',
    inputText: '',
    followTitle:'关注',
    collectionTitle:'收藏',
    isScore:''
  },
  compiled:function(){
    var _self = this;
    
    //文档删除
    $(document).on('click','.ooo',function(){
        _self.addShow = false;
        alert({
            close:false,
            text: '是否将其删除？',
            kind: 2,
            okEvent: function(){
                _self.deleteArticle();
            }
        });
    });
    
    $(document).on('click','.scoreBox i',function(){
        if(!$(this).hasClass('on')){
            $(this).addClass('on').prevAll().addClass('on');
            $('.pop_sure').css('color','#fff').removeClass('not');
        }else{
            $(this).removeClass('on').nextAll().removeClass('on');
        }
        if($('.scoreBox i.on').length==0){
            $('.pop_sure').css('color','#a4d7fa').addClass('not');
        }
        _self.score = $(".scoreBox i[class='on']").length;
    });
    $(document).on('change.inputText','.fillInput',function(){
        _self.inputText = $(this).val();
    });
  },
  created:function(){
    var dtd = $.Deferred();
    var _self = this;

    //文档详情
    var data = {
        articleID : articleID,
        annexID : annexID
    };
    data = Common.jsonEncode(data);
    Common.ajaxCall({ url: 'look_getAnnexDetail', datatype: 'json', type: 'post', data: data}, function (data) {
        if(data.error_code==0){
            var obj = data.data[0];
            _self.title = obj.title;
            _self.info = obj;
            if(obj.hideTitle == 1){ //show
                _self.showHeader();
            }
           var fontSize = parseInt($('html').css('fontSize'));  //获取当前屏幕的字体
            //文档资料
           var viewer = EdoViewer.createViewer('viewer', {
             width: $(window).width(),
             height: $(window).height(),
             mode: obj.showType
           });
           viewer.load_from_wo(obj.content);
            
        }else{
            alert(data.msg);
        }
    });

    var fontSize = parseInt($('html').css('fontSize'));  //获取当前屏幕的字体
    //$('#artIframe').height($(document).height()-$('.header').height()-2.3*fontSize);
    $('#viewer').height($(window).height());
    //$('#viewer').css('overflow-y','scroll');
    
  },
  methods:{
    showHeader: function (e) {
        var fontSize = parseInt($('html').css('fontSize'));  //获取当前屏幕的字体
        if($('#header').css('display')==='none'){
            if($('#viewer').length>0) $('#viewer').height($(window).height()-2.3*fontSize);
            
            $('#viewer-viewer').height($('#viewer-viewer').height()-2.3*fontSize);
            $('#section').css('paddingTop',2.3*fontSize);
            $('#header').show();
            
        }else{
            if($('#viewer').length>0) $('#viewer').height($(window).height());
            if($('#viewer-viewer').length>0){
                $('#viewer-viewer').height($(window).height());
                $('#section').css('paddingTop','0');
                $('#header').hide();
            }
        }
    },
    //文档删除
    deleteArticle:function(){
        var _self = this;
        var data = {
            articleID: articleID,
            annexID:annexID
        };
        data = Common.jsonEncode(data);
        Common.ajaxCall({ url: 'look_deleteAnnexID', datatype: 'json', type: 'post', data: data}, function (data) {
            alert(data.msg);
            setTimeout(function(){ _self.back();},1000);
        });
    },
    add:function(){
        if(this.addShow == false){
            this.addShow = true;
        }else{
            this.addShow = false;
        }
    },
    back:function(){
      window.location.href = decodeURIComponent(backUrl);
    }
  },
  watch:{

  }
});



